#ifndef D2E0C426_A09E_4970_A570_F464C9DF4C20
#define D2E0C426_A09E_4970_A570_F464C9DF4C20

#include <cstring>
#include <errno.h>
#include "nocopy.hpp"
class epoller : public nocopy
{
	const int size = 1024;
public:
	epoller()
	{
		epfd_ = epoll_create(size);
		if(epfd_ == -1){
			lg(Error,"create fd error,errno : %d , errstring: %s",errno,strerror(errno));
		}
		else{
			lg(Info,"create epfd success,epfd_ : %d",epfd_);
		}
	}
	void EpollerUpdate(int oper,int fd,uint32_t event)
	{
		epoll_event en;
		if(oper == EPOLL_CTL_DEL){
			int n = epoll_ctl(epfd_,oper,fd,nullptr);
			if(n == -1){
				lg(Warnning,"epoll_ctl delete error,errstring:%s",strerror(errno));
			}
		}
		else if(oper & EPOLL_CTL_ADD | oper & EPOLL_CTL_MOD)
		{
			en.events = event;
			en.data.fd = fd;
			int n = epoll_ctl(epfd_,oper,fd,&en);
			if(n == -1){
				lg(Warnning,"epoll_ctl error,errstring:%s",strerror(errno));
			}
		}
		else{

		}
	}

	int EpollerWait(epoll_event resv[],int num)
	{
		int n = epoll_wait(epfd_,resv,num,-1);
		return n;
	}
	~epoller(){}
private:
	int epfd_;	
};

#endif /* D2E0C426_A09E_4970_A570_F464C9DF4C20 */
